package com.ming.mq.topic;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicConfig {
    public static final String TOPICQUEUE1 = "queue_topic01";
    public static final String TOPICQUEUE2 = "queue_topic02";
    public static final String TOPICEXCHANGE = "topicExchange";
    public static final String ROUTINGKEY1 = "#.queue.#";
    public static final String ROUTINGKEY2 = "*.queue.#";

    @Bean
    public Queue topicQueue1(){
        return new Queue(TOPICQUEUE1);
    }

    @Bean
    public Queue topicQueue2(){
        return new Queue(TOPICQUEUE2);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(TOPICEXCHANGE);
    }

    @Bean
    public Binding binding1(){
        return BindingBuilder.bind(topicQueue1())
                .to(topicExchange())
                .with(ROUTINGKEY1);
    }

    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(topicQueue2())
                .to(topicExchange())
                .with(ROUTINGKEY2);
    }


}
